package com.itmuch.cloud.feign;

import com.itmuch.cloud.entity.User;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author: chenhs
 * @date: Created in 6:57 2020/1/27
 **/
@Component
public class HystrixClientFallbackFactory implements FallbackFactory<UserFeignClient> {

    private static final Logger LOGGER = LoggerFactory.getLogger(HystrixClientFallbackFactory.class);

    @Override
    public UserFeignClient create(Throwable cause) {

        HystrixClientFallbackFactory.LOGGER.info("fallback reason was : {} ", cause.getMessage());

        return (UserFeignClientFactory) user -> {
            User u = new User();
            u.setId(-1L);
            return u;
        };
    }
}
